<%-- 
    Document   : EditCar
    Created on : Nov 1, 2011, 11:43:10 PM
    Author     : Mr-aUgust
--%>

<%@page pageEncoding="UTF-8"%>
<%@ page language="java" import="javazoom.upload.*,java.util.*" %>
<%@ page session="true" import="java.util.Collection, DAL.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<%
        session.removeAttribute("status");
        session.removeAttribute("statusH");
        
        String im="";
        try{
        if (MultipartFormDataRequest.isMultipartFormData(request))
                      {
                         MultipartFormDataRequest mrequest = new MultipartFormDataRequest(request);
                         UploadBean upBean=new UploadBean();
                         upBean.setFolderstore(getServletContext().getRealPath("/") + "images\\car");
                         String todo = null;
                         if (mrequest != null) todo = mrequest.getParameter("todo");
                             if ( (todo != null) && (todo.equalsIgnoreCase("upload")) )
                             {
                                Hashtable files = mrequest.getFiles();
                                if ( (files != null) && (!files.isEmpty()) )
                                {
                                    UploadFile file = (UploadFile) files.get("uploadfile");
                                    if (file != null) //out.println("<li>Form field : uploadfile"+"<BR> Uploaded file : "+file.getFileName()+" ("+file.getFileSize()+" bytes)"+"<BR> Content Type : "+file.getContentType());
                                    // Uses the bean now to store specified by jsp:setProperty at the top.
                                        im="images/car/"+file.getFileName();
                                    upBean.store(mrequest, "uploadfile");
                                  //  out.println("<li> uploaded files success");
                                  //  out.println(getServletContext().getRealPath("/")+ "images\\car");
                                }
                                else
                                {
                                  out.println("<li>No uploaded files");
                                }
                             }
                   else out.println("<BR> todo="+todo);
                  }
            }catch (Exception ex){}
 %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>East2West Tours and Travels</title>
        <link rel="stylesheet" href="../WebContent/css/jquery.wysiwyg.css" type="text/css" />
        <link rel="stylesheet" href="examples.css" type="text/css" />
        <script src="../js/jqueryvalidate.js" type="text/javascript"></script>
        <script src="../js/jquery.validate.js" type="text/javascript"></script>
        <script type="text/javascript">            
            $(document).ready(function() {
            $("#FormUpload").validate
                ({
                    rules:{
                        uploadfile:{ required: true}
                    },
                    messages: {
                        uploadfile:{required:"*"}   
                        }            
                });   
                
            });
            $(document).ready(function() {
            $("#FormInfoUpload").validate
                ({
                    rules:{
                        carname:{ required: true},
                        seating:{required: true,digits: true},
                        driver:{required: true,digits: true},
                        PriceDate:{required: true},
                        PriceHour:{required: true},
                        Pricekilomet:{required: true}
                    },
                    messages: {
                           carname:{ required: "*"},
                           seating:{required: "*",digits: "Please enter only digits"},
                           driver:{required: "*",digits: "Please enter only digits"},
                           PriceDate:{required: "*"},
                           PriceHour:{required: "*"},
                           Pricekilomet:{required: "*"}
                    }            
                });     
            });
            
    </script>
        
       <style type="text/css">
            #khun
            {
                margin-left:auto;
                margin-right:auto;
                width:600px;
                height:730px;
                background-color:#dfe0dd;
                margin-top:20px;
            }
            table
            {
                margin-left:auto;
                margin-right:auto;
            }
            .font
            {
                font-family:"Times New Roman", Times, serif;
                font-size:x-large;
                font-weight:bold;
                width:200px;
                height:20px;
                margin-left:auto;
                margin-right:auto;
                color:#0707e7;
            }
            .sizeeditcar
            {
            width:100px;
            }
        </style>  
    </head>
    <body>
        <div id="khun">
        <div class="font">Edit Car</div>
        <br><br>
          <%
            String carid="",image="",carname="",seating="",conditioner="",driver="",PriceDate="",Pricehour="",Pricekilomet="",CarType="",ModelCar="",wysiwyg="";
                if(session.getAttribute("carid")!=null)
                 {
                    carid=session.getAttribute("carid").toString();
                    image=session.getAttribute("image").toString();
                    carname=session.getAttribute("carname").toString();
                    seating=session.getAttribute("seating").toString();
                    conditioner=session.getAttribute("conditioner").toString();
                    driver=session.getAttribute("driver").toString();
                    PriceDate=session.getAttribute("PriceDate").toString();
                    Pricehour=session.getAttribute("Pricehour").toString();
                    Pricekilomet=session.getAttribute("Pricekilomet").toString();
                    CarType=session.getAttribute("CarType").toString();
                    ModelCar=session.getAttribute("ModelCar").toString();
                    wysiwyg=session.getAttribute("wysiwyg").toString();       
                 }
          %>
                    
            <form action="management.jsp?page=EditCar" method="post" id="FormUpload" name="upform" enctype="multipart/form-data">
                <table border="0" cellpadding="1" cellspacing="1" width="500px">
                    <tr>
                        <td>Choose Image:</td>
                        <td align="left" style="color:red;">
                            <input type="file" name="uploadfile" size="25">
                            <input type="hidden" name="todo" value="upload">
                            <input type="submit" name="Submit" value="Upload">
                        </td>
                    </tr>
                </table>
            </form>
            <form action="../ControllerCar" method="get" id="FormInfoUpload" name="car" enctype="multipart/form-data">
                <table border="0" cellpadding="1" cellspacing="1" width="500px">
                <tr>
                    <td></td>
                    <td>
                       <% if(im !="")
                        {
                       %>
                            <img src="../<%=im%>"  width="150px" height="100px" />
                            <input type="hidden" name="image" value="<%=im%>" />
                        <%
                        }
                        else
                            {
                            %>                            
                            <img src="../<%=image%>"  width="150px" height="100px" />
                            <input type="hidden" name="imageDB" value="<%=image%>" />                            
                            <%
                            }
                        %>
                    </td>
                </tr>
                <tr>
                    <td>CarID:</td>
                    <td style="color:red;">
                         <input type="hidden" name="CarID" value="<%=carid%>" />
                         <label><%=carid%></label>
                    </td>
                </tr>
                <tr>
                    <td>CarName:</td>
                    <td style="color:red;"><input type="text" name="carname" maxlength="90" value="<%=carname%>" size="25"/></td>
                </tr>
                <tr>
                    <td>Seating:</td>
                    <td style="color:red;"><input type="text" name="seating" maxlength="3" value="<%=seating%>" size="25"/></td>
                </tr>
                <tr>
                    <td>Air_conditioner:</td>                        
                    <td>
                        <%
                            if(conditioner.equals("Yes"))
                                {
                        %>
                                 <input type="radio" name="conditioner" value="Yes" checked="true" />Yes
                                 <input type="radio" name="conditioner" value="No" />No
                            <%
                            }
                            else
                                {
                                %>
                                <input type="radio" name="conditioner" value="Yes" />Yes
                                <input type="radio" name="conditioner" value="No" checked="true" />No
                                <%
                                }
                            %>
                     </td>
                </tr>
                 <tr>
                    <td>Quantity:</td>                        
                    <td style="color:red;">
                        <input type="text" name="driver" maxlength="4" value="<%=driver%>" size="25"/>
                     </td>
                </tr>
                <tr>
                    <td>PriceDate:</td>
                    <td style="color:red;"><input type="text" name="PriceDate" maxlength="15" value="<%=PriceDate%>" size="25"/></td>
                </tr>
                <tr>
                    <td>PriceHour:</td>
                    <td style="color:red;"><input type="text" name="PriceHour" maxlength="15" value="<%=Pricehour%>" size="25"/></td>
                </tr>
                <tr>
                    <td>Pricekilomet:</td>
                    <td style="color:red;"><input type="text" name="Pricekilomet" maxlength="15" value="<%=Pricekilomet%>" size="25"/></td>
                </tr>
                <tr>
                    <td>CarType:</td>
                    <td>
                        <select name="CarType" >
                            <%
                            if(CarType.equals("Small Size"))
                                {
                                %>
                                <option value="Small Size" selected>Small Size</option>
                                <%
                                }
                                else if(CarType.equals("Full Size"))
                                {
                                %>
                                  <option value="Full Size" selected>Full Size</option>
                                <%
                                }
                                else if(CarType.equals("Luxury"))
                                {
                                %>
                                    <option value="Luxury" selected>Luxury</option>
                                <%
                                 }
                                 else
                                 {
                                 %>
                                 <option value="Minivan" selected>Minivan</option>
                                 <%
                                 }
                            %>
                            <option value="Small Size">Small Size</option>
                            <option value="Full Fize">Full Fize</option>
                            <option value="Luxury">Luxury</option>
                            <option value="Minivan">Minivan</option>
                        </select>
                    </td>
                </tr>
                <%
                 ModelCarBean mc=new ModelCarBean();
                 Collection collec=mc.ModelCarEditDrop(ModelCar);
                 request.setAttribute("mcar",collec);
                %>
                <tr>
                    <td>Model Car</td>
                    <td>
                        <select name="ModelCar" >
                        <c:forEach items="${mcar}" var="mocar">                        
                            <option value="${mocar.modelID}" ${mocar.editDrop}>${mocar.modelName}</option> 
                        </c:forEach>
                        </select>
                    </td>
                </tr>
            
                <tr>
                    <td>Desciption:</td>
                    <td><textarea name="wysiwyg" id="wysiwyg" rows="10" cols="40"><%=wysiwyg%></textarea></td>
                </tr>
                <tr>
                    <td colspan="2"></td>
                </tr>
                <tr>
                    <td align="right"><input type="submit" class="sizeeditcar" name="update" value="Update" /></td>
               </form>
               <td>
                 <form action="management.jsp?page=ListCars" name="cancel" method="post">
                     <input type="submit" value="Cancel" class="sizeeditcar"/> 
                 </form> 
                </td>
           </tr>              
        </table> 
        </div> 
        
        <script type="text/javascript" src="../WebContent/jquery/jquery.wysiwyg.js"></script> 
        <script type="text/javascript">
                 $(function()
                    {
                       $('#wysiwyg').wysiwyg();
                    });
       </script>
    </body>
</html>

